package com.sky.mapper;

import com.sky.anno.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     *
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into dish values (null,#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insertDish(Dish dish);

    List<DishVO> getPage(DishPageQueryDTO dto);

    int countByStatus(List<Long> ids);

    void deleteBatch(List<Long> ids);

    @Select("select * from dish where id = #{id}")
    Dish getDish(Long id);

    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);

    List<DishVO> getDishesByCategoryId(Long categoryId,Integer status);
}
